import request from "@/axios/request.js";
import { method } from "lodash";

//========================用户操作==============================

export function getCodeAPI() {
  return request.get(`/code`);
}

export function userLoginAPI(data) {
  return request.post(`/judge-backend/login`, data);
}

export function userRegisterAPI(data) {
  return request.post(`/judge-backend/reg`, data);
}

export function userInfoAPI() {
  return request.get("/judge-backend/userinfo/me");
}

export function userLogOutAPI() {
  return request.get(`/judge-backend/logout`);
}

export function updateUserPhoneAPI(data) {
  return request.put(`/judge-backend/userinfo/phone`, data);
}

export function updateUserEmailAPI(data) {
  return request.put(`/judge-backend/userinfo/email`, data);
}

export function updateUserInfoAPI(userInfo) {
  return request.put(`/judge-backend/userinfo`, userInfo);
}

export function updatePwdAPI(data) {
  return request.put(`/judge-backend/userinfo/password`, data);
}

//=========================题库题目接口============================
export function getProblemListAPI(data) {
  return request.get(
    `/judge-backend/problem/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}&difficulty=${data.difficulty}&name=${data.name}`
  );
}

export function getProblemAPI(id) {
  return request.get(`/judge-backend/problem?pid=${id}`);
}

export function randomAProblemAPI() {
  return request.get(`/judge-backend/problem/random`);
}

export function dailyAProblemAPI() {
  return request.get(`/judge-backend/problem/daily`);
}

export function getTagAPI() {
  return request.get("/judge-backend/tag/category");
}

export function getCodeTempaletAPI(pid) {
  return request.get(`/judge-backend/problem/codetemplate?pid=${pid}`);
}
//=========================评测接口============================
export function getJudgeListAPI(data) {
  return request({
    url: "/judge-backend/judge/list",
    method: "GET",
    params: {
      ...data,
    },
  });
}

export function getJudgeDetailListAPI(id) {
  return request.get(`/judge-backend/judgecase?submitId=${id}`);
}

export function getJudgeDetailAPI(id) {
  return request.get(`/judge-backend/judge?submitId=${id}`);
}

//=========================提交接口============================
export function submitAPI(code) {
  return request.post(`/judge-backend/judge/submit`, code);
}

export function submitDebugAPI(data) {
  return request.post(`/judge-backend/judge/submit/testJudge`, data);
}

export function getDebugDetailAPI(cacheKey) {
  return request.get(`/judge-backend/judge/testJudge?cacheKey=${cacheKey}`);
}

export function reSubmitAPI(data) {
  return request({
    url: "/judge-backend/manage/Judge/reJudge",
    method: "PUT",
    params: {
      ...data,
    },
  });
}
export function getDetailBySubmitIdAPI(id) {
  return request.get(`/judge-backend/judge?submitId=${id}`);
}
//=========================讨论接口============================
export function discussAPI(discuss) {
  return request.post("/judge-backend/discussion", discuss);
}

export function updateDiscussAPI(data) {
  return request.put("/judge-backend/discussion", data);
}

export function getDiscussAPI(data) {
  let tagList = "";
  data.tagList.forEach((item, index) => {
    if (index === data.tagList.length - 1) {
      tagList += item;
    } else {
      tagList += item + ",";
    }
  });

  return request.get(
    `/judge-backend/discussion/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}&categoryId=${data.categoryId}&like=${data.like}&tagList=${tagList}&pid=${data.pid}`
  );
}

export function getCommentAPI(commentId) {
  return request.get(`/judge-backend/replay/list?commentId=${commentId}`);
}

export function getMyDiscussionAPI(data) {
  return request.get(
    `/judge-backend/discussion/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}&categoryId=${data.categoryId}&like=${data.like}`,
    data.tagList
  );
}

export function getDiscussDetail(discussId) {
  return request.get(`/judge-backend/discussion/detail?id=${discussId}`);
}

export function getDisscussCategoryAPI() {
  return request.get("/judge-backend/category/list");
}

export function categoryAPI(category) {
  return request.post("/judge-backend/admin/category", category);
}
export function delDiscussAPI(data) {
  return request.delete("/judge-backend/discussion", {
    data,
  });
}
export function reportDiscussAPI(data) {
  return request.post("/judge-backend/report", data);
}
//=========================消息管理接口============================
export function getLikeMeAPI(pageNum, pageSize = 7) {
  return request.get(
    `/judge-backend/message/like-me/list?pageNum=${pageNum}&pageSize=${pageSize}`
  );
}
export function getCommentMeAPI(pageNum, pageSize = 4) {
  return request.get(
    `/judge-backend/message/comment-me/list?pageNum=${pageNum}&pageSize=${pageSize}`
  );
}
export function getReplyMeAPI(pageNum, pageSize = 4) {
  return request.get(
    `/judge-backend/message/replay-me/list?pageNum=${pageNum}&pageSize=${pageSize}`
  );
}
export function getNoticeMeAPI(pageNum, pageSize = 5) {
  return request.get(
    `/judge-backend/message/notice-me/list?pageNum=${pageNum}&pageSize=${pageSize}`
  );
}
export function getMineMeAPI(pageNum, pageSize = 5) {
  return request.get(
    `/judge-backend/message/message-me/list?pageNum=${pageNum}&pageSize=${pageSize}`
  );
}
export function delOneNoticeAPI(data) {
  return request.delete("/judge-backend/message", { data });
}
export function delAllNoticeAPI(data) {
  return request.delete("/judge-backend/message/all", { data });
}
export function getNoticeNumAPI() {
  return request.get("/judge-backend/message/num");
}

//=========================讨论分类接口============================
export function updateCategoryAPI(category) {
  return request.put("/judge-backend/admin/category", category);
}
export function updateDiscussLikeAPI(data) {
  return request.post("/judge-backend/discussion/like", data);
}
export function deleteCategoryAPI(data) {
  return request.delete("/judge-backend/admin/category", data);
}
//=========================讨论评论接口============================
export function addReplayAPI(data) {
  return request.post("/judge-backend/comment", data);
}

export function getReplayAPI(data) {
  return request.get(
    `/judge-backend/comment/list?pageSize=10&pageNum=${data.pageNum}&discussionId=${data.discussionId}`
  );
}

export function likeCommentAPI(data) {
  return request.post("/judge-backend/comment/like", data);
}

export function addCommentAPI(data) {
  return request.post("/judge-backend/reply", data);
}

//=========================训练接口============================
export function getTrainingListAPI(data) {
  return request.get(
    `/judge-backend/training/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}&title=${data.title}&categoryId=${data.categoryId}&auth=${data.auth}`
  );
}

export function getTraingCategoryAPI() {
  return request.get(`/judge-backend/training/category/list`);
}

export function getTrainingDetailAPI(id) {
  return request.get(`/judge-backend/training/getById?tid=${id}`);
}

export function getTrainingProblemListAPI(data) {
  return request.get(
    `/judge-backend/trainingProblem/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}&tid=${data.tid}`
  );
}

export function getProblemStatusAPI(ids) {
  return request.post(`/judge-backend/problem/list/status`, ids);
}

export function getTrainingAuthAPI(id) {
  return request.get(`/judge-backend/training/getTrainingAccess?tid=${id}`);
}

export function trainingPasswdAPI(tid, passwd) {
  return request.post(
    `/judge-backend/training/addTrainingAccess?tid=${tid}&password=${passwd}`
  );
}

//=========================排行接口============================
export function getACMRankListAPI(data) {
  return request.get(
    `/judge-backend/ranking/acm?username=${data.username}&pageNum=${data.pageNum}&pageSize=${data.pageSize}`
  );
}

export function getOIRankListAPI(data) {
  return request.get(
    `/judge-backend/ranking/oi?username=${data.username}&pageNum=${data.pageNum}&pageSize=${data.pageSize}`
  );
}

export function reLoadACMAPI() {
  return request({
    url: "/judge-backend/ranking/acmRebuild",
    method: "GET",
  });
}
export function reLoadOIAPI() {
  return request({
    url: "/judge-backend/ranking/oiRebuild",
    method: "GET",
  });
}
//=========================前台公告接口============================
export function getNoticeAPI(data) {
  return request.get(
    `/judge-backend/announcement/list?pageNum=${data.pageNum}&pageSize=${data.pageSize}&like=${data.like}`
  );
}

//========================比赛操作==============================
export function getRaceListAPI(data) {
  return request.get(
    `/judge-contest/contest?pageNum=${data.pageNum}&pageSize=${data.pageSize}&name=${data.name}&format=${data.format}&status=${data.status}`
  );
}

export function getRaceProblemDetailAPI(cid, cpid) {
  return request.get(
    `/judge-contest/contest/problem/info?cid=${cid}&cpid=${cpid}`
  );
}

export function getRaceDetailAPI(id) {
  return request.get(`/judge-contest/contest/info?cid=${id}`);
}

export function userIsRegisterRaceAPI(cid) {
  return request.post(`/judge-contest/contest/user/is/reg?cid=${cid}`);
}

export function userRegisterRaceAPI(data) {
  return request.post(
    `/judge-contest/contest/reg?cid=${data.cid}&pwd=${data.pwd}`
  );
}

export function getRaceTeamsAPI(data) {
  return request.get(
    `/judge-contest/contest/group?cid=${data.cid}&pageNum=${data.pageNum}&pageSize=${data.pageSize}`
  );
}

export function getUserTeamAPI(cid) {
  return request.get(`/judge-contest/contest/group/me?cid=${cid}`);
}

export function userCreateTeamAPI(data) {
  return request.post(
    `/judge-contest/contest/group?cid=${data.cid}&name=${data.name}`
  );
}

export function userUpdateTeamAPI(data) {
  return request.put(
    `/judge-contest/contest/group?cid=${data.cid}&name=${data.name}`
  );
}

export function userJoinTeamAPI(cgid) {
  return request.post(`/judge-contest/contest/group/join?cgid=${cgid}`);
}

export function userDelTeamAPI(cid) {
  return request.delete(`/judge-contest/contest/group?cid=${cid}`);
}

export function getUserApplicationsAPI(data) {
  return request.post(
    `/judge-contest/contest/regs?isManage=${data.isManage}&cid=${data.cid}&pageNum=${data.pageNum}&pageSize=${data.pageSize}&type=${data.type}&status=${data.status}&cgid=${data.cgid}`
  );
}

export function userDealApplicationsAPI(data) {
  return request.put(
    `/judge-contest/contest/regs?cgrId=${data.cgrId}&status=${data.status}`
  );
}

export function leaderGetUsersAPI(data) {
  return request.get(
    `/judge-contest/contest/user?cid=${data.cid}&pageNum=${data.pageNum}&pageSize=${data.pageSize}`
  );
}

export function leaderInviteUserAPI(data) {
  return request.post(
    `/judge-contest/contest/group/invite?cid=${data.cid}&uid=${data.uid}`
  );
}

export function leaderDelUserAPI(data) {
  return request.delete(
    `/judge-contest/contest/user?cid=${data.cid}&uid=${data.uid}`
  );
}

export function getTeamUserCountAPI(ids) {
  return request.post(`/judge-contest/contest/group/count`, ids);
}

export function getRaceProblemAPI(cid) {
  return request.get(`/judge-contest/contest/problem?cid=${cid}`);
}

export function getRaceEvoluationAPI(data) {
  return request.get(
    `/judge-contest/contest/judge?cid=${data.cid}&pageNum=${data.pageNum}&pageSize=${data.pageSize}&status=${data.status}&pid=${data.pid}&username=${data.username}`
  );
}

export function userSubmitRaceAPI(cid, cpid, data) {
  return request.post(
    `/judge-contest/contest/judge?cid=${cid}&cpid=${cpid}`,
    data
  );
}
export function getRaceNoticeAPI(data) {
  return request.get(
    `/judge-contest/contest/notice?pageNum=${data.pageNum}&pageSize=${data.pageSize}&cid=${data.cid}&like=${data.like}`
  );
}
export function getRaceProblemAcAPI(cid, data) {
  return request.post(
    `/judge-contest/contest/problem/status/count?cid=${cid}`,
    data
  );
}
export function getRaceProblemScoreAPI(cid, data) {
  return request.post(`/judge-contest/contest/problem/scores?cid=${cid}`, data);
}

export function getRaceProblemStatusAPI(cid, data) {
  return request.post(
    `/judge-contest/contest/judge/list/status?cid=${cid}`,
    data
  );
}
//========================比赛排名==============================
export function getRaceRankAPI(data) {
  return request.post(
    `/judge-contest/contest/rank/user?pageNum=${data.pageNum}&pageSize=${data.pageSize}&removeStar=${data.removeStar}&cid=${data.cid}&keyword=${data.keyword}`
  );
}
export function getRaceTeamRankAPI(data) {
  return request.post(
    `/judge-contest/contest/rank/group?pageNum=${data.pageNum}&pageSize=${data.pageSize}&removeStar=${data.removeStar}&cid=${data.cid}&keyword=${data.keyword}`
  );
}
//========================任务列表==============================
export function getTaskListAPI(data) {
  return request({
    url: "/judge-backend/task/record/list",
    method: "GET",
  });
}
export function getTaskDataAPI(data) {
  return request({
    url: "/judge-backend/task/record",
    method: "GET",
    params: {
      ...data,
    },
  });
}

export function getSettingColorAPI() {
  return request.get(`/judge-backend/sys/config/background/color`);
}
